require.config({baseUrl: '/js/lib',urlArgs: "v0.0.1"});
require(['zepto', 'lib'], function($, lib) {
  var fn = {}, lib = new lib();
  $.extend(fn, {
    timeInterVal: null,
    init: function(){
      var _t = this;
      _t.bindEvent();
    },
    bindEvent: function(){
      var _t = this;
      /*监测输入框*/
      $("input[name=userCode]").keyup(function(){
        if($(this).val().trim().length > 0 && !$(".ui-red-botton").hasClass('ui-ing')){
          $(".ui-red-botton").removeClass("ui-disable");
        }else{
          $(".ui-red-botton").addClass("ui-disable");
        }
      });
      
      /*点击登陆按钮*/
      $(document).on("tap", ".ui-red-botton:not(.ui-disable)", function(data){
        var _this = this;
        $(_this).addClass("ui-ing ui-disable");
        if(!_t.checkTel($("input[name=userTel]").val())){
          lib.showMessage("请输入正确的手机号");
          $(_this).removeClass("ui-ing ui-disable");
          return;
        }
        if($("input[name=userCode]").val().trim().length === 0){
          lib.showMessage("请输入密码");
          $(_this).removeClass("ui-ing ui-disable");
          return;
        }
        lib.onLoading();
        lib.ajx(lib.getReq().ser + 'user/login.action', {username: $("input[name=userTel]").val(), password: $("input[name=userCode]").val()}, function(data){
          if(data.infocode === "0"){
            location.href = lib.getUrlParam("backUrl") || '/seller/index.html';
          }else{
            lib.showMessage(data.info);
          }
          $(_this).removeClass("ui-ing ui-disable");
          
        }, function(){
          lib.showMessage("网络超时，请稍后再试");
          $(_this).removeClass("ui-ing ui-disable");
        });
      });
    },
    checkTel: function(num){
      var numReg = /^1[34578]\d{9}$/;
      return numReg.test(num);
    }
  });
  
  fn.init();
});